<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<style>

    .tuiren{display: none}

    #commentForm .main-container{padding-bottom: 50px!important;}
    .main-container{padding-top: 10px!important;}
    .add-tag{margin: 5px 0}
    .mainBox{bottom: 0!important;}
    .xuanmsg{color: #aaa;margin: 9px 0 5px 11px;font-size: 12px}
    .page-title{border-bottom: 10px solid #ecf0f1;}
    .bottss{width: 100%;height: 30px;position: fixed;bottom: 0;}

</style>
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title">
        <div class="page-title-con"><span>退回</span><div class="move_title"></div><?php include "../public/sub.php";?></div>
    </div>
    <div class="main-container">
        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label" style="height: 72px;line-height: 44px"><text style="color: red">*</text>退回到</label>
                        <div class="layui-input-block" style="height: 56px">
                            <div class="radio-block">
                                <input type="radio" name="tuitype" class="tuitype1" lay-filter="tuitype" checked value="1" title="指定审核人">
                                <input type="radio" name="tuitype" class="tuitype2" lay-filter="tuitype" value="2" title="指定节点">
                                <div class="xuanmsg" id="tuitypemsg">退回指定审核人，该审核人通过成后进入下一节点。</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item" id="tuiren_ren">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text style="color: red">*</text>选择审核人</label>
                        <div class="layui-input-block">
                            <select id="renid" name="renid" lay-filter="renid" >
                                <option value="">请选择</option>
                            </select>
                            <p class="error" id="renid_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item tuiren" id="tuiren_jie">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text style="color: red">*</text>选择节点</label>
                        <div class="layui-input-block">
                            <select id="jieid" name="jieid" lay-filter="jieid" >
                                <option value="">请选择</option>
                            </select>
                            <p class="error" id="jieid_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item" id="tuiren_tiao">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label" style="height: 88px;line-height: 44px"><text style="color: red">*</text>智能跳过</label>
                        <div class="layui-input-block" style="height: 73px">
                            <div class="radio-block">
                                <input type="radio" name="tiaotype" lay-filter="tiaotype" checked value="1" title="是">
                                <input type="radio" name="tiaotype" lay-filter="tiaotype" value="2" title="否">
                                <div class="xuanmsg" id="tiaotypemsg">被退回的节点或审核人完成审核后，将自动跳过此前已经审核通过的节点，回到操作退回的审核人。</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item" id="tuiren_chong">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label" style="height: 72px;line-height: 44px"><text style="color: red">*</text>申请人提交</label>
                        <div class="layui-input-block" style="height: 56px">
                            <div class="radio-block">
                                <input type="radio" name="chongtype" class="chongtype1" lay-filter="chongtype" checked value="1" title="重走流程">
                                <input type="radio" name="chongtype" class="chongtype2" lay-filter="chongtype" value="2" title="直接返回">
                                <div class="xuanmsg" id="chongtypemsg">申请人重新提交后，系统根据申请人编辑后的内容匹配路线并重走。</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>



            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12 tes_box">
                        <label class="layui-form-label tes_label">处理意见</label>
                        <div class="layui-input-block tes_block" style="margin-left: 0 !important;">
                            <input type="hidden" name="agree" value="3">
                            <input type="text" name="explain" id="explain" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                            <div style="color: #1ca5ff;cursor: pointer;display: inline-block" class="add-tag" onclick="addFlowUsed()">加入常用说明</div>
                            <div class="tag-box" id="flow_used_div"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="qianshen">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label" style="height: 98px;line-height: 84px"><text>*</text>手写签名</label>
                        <div class="layui-input-block signshen">
                            <div class="deaqian deadea" onclick="openPage('flow_signshen.php')">
                                <span class="iico"><i class="layui-icon layui-icon-edit"></i></span>
                                <span class="qiantxt">点此签名</span>
                            </div>
                            <div class="deaqian deazhen layui-hide">
                                <img src="">
                                <i class="layui-icon layui-icon-close iiclose" onclick="delQian()"></i>
                                <input type="hidden" id="qian_id" name="qian_id">
                                <input type="hidden" id="qian" name="qian">
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <?php include '../public/upinfotwo.php'?>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">抄送</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=promer&type=user&single=2');"></div>
                                <div class="tanxiannei" id="promer"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=promer&type=user&single=2');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</form>
<div class="bottss"></div>
<script>
    var param_id = getQueryVariable('id') || 0;
    var param_isqian = getQueryVariable('isqian') || 0;
    if(param_isqian == 1){
        $("#qianshen").removeClass('layui-hide');
    }
    function delQian (){
        $(".signshen .deadea" ).removeClass('layui-hide');
        $(".signshen .deazhen").addClass('layui-hide');
        $(".signshen .deazhen img").attr('src', '');
        $("#qian_id").val('');
        $("#qian").val('');
    }

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;

        public_upload_file_load('upload_files');


        facade.ajax({url: ask_opt_get_flow_tui_info, data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                if(res.data.nodetype == 2){
                    $(".tuitype1").prop('disabled', true);
                    $(".tuitype1").prop('disabled', true);
                    $(".tuitype2").prop('checked', true);

                    $("#tuitypemsg").text('退回指定节点，该节点整体重审，通过后进入后续节点。');
                    $("#tuiren_ren").hide();
                    $("#tuiren_jie").show();

                    var jieidArr = res.data.listJie;
                    for (var key in jieidArr){
                        jieid_str += '<option value="'+jieidArr[key].id+'">'+jieidArr[key].name+'</option>';
                    }
                    $('#jieid').html(jieid_str);

                    $("#tuiren_chong").show();
                    $("#tuiren_tiao").hide();

                    $(".chongtype1").prop('disabled', true);
                    $(".chongtype2").prop('disabled', true);
                }else{
                    var renid_str = '<option value="">请选择</option>';
                    var renidArr = res.data.listRen;
                    for (var key in renidArr){
                        renid_str += '<option value="'+renidArr[key].id+'">'+renidArr[key].name+'</option>';
                    }
                    $('#renid').html(renid_str);


                    var jieid_str = '<option value="">请选择</option>';
                    var jieidArr = res.data.listJie;
                    for (var key in jieidArr){
                        jieid_str += '<option value="'+jieidArr[key].id+'">'+jieidArr[key].name+'</option>';
                    }
                    $('#jieid').html(jieid_str);
                }

                render_from();
            }
        });


        facade.ajax({url: ask_opt_get_flow_used}).done(function(res){
            if (res.code === 2000) {
                show_flow_used(res.data);
                render_from();
            }
        });

        form.on('radio(tuitype)',function (data) {
            if(data.value == 1){
                $("#tuitypemsg").text('退回指定审核人，该审核人通过成后进入下一节点。');
                $("#tuiren_ren").show();
                $("#tuiren_jie").hide();
                $("#tuiren_chong").hide();
                $("#tuiren_tiao").show();
            }else{
                $("#tuitypemsg").text('退回指定节点，该节点整体重审，通过后进入后续节点。');
                $("#tuiren_ren").hide();
                $("#tuiren_jie").show();

                if($("#jieid").val() == 0 && $("#jieid").val() != ''){
                    $("#tuiren_chong").show();
                    $("#tuiren_tiao").hide();
                }else{
                    $("#tuiren_chong").hide();
                    $("#tuiren_tiao").show();
                }
            }
        });


        form.on('select(jieid)',function (data) {
            if(data.value == 0 && data.value != ''){
                $("#tuiren_chong").show();
                $("#tuiren_tiao").hide();
            }else{
                $("#tuiren_chong").hide();
                $("#tuiren_tiao").show();
            }

            if(data.value == ''){
                $('#jieid_error').show().text('请选择');
                $('#jieid_error').parent().find('input').addClass('select_error');
            }else{
                $('#jieid_error').hide();
                $('#jieid_error').parent().find('input').removeClass('select_error');
            }
        });

        form.on('select(renid)', function(data){
            if(data.value == ''){
                $('#renid_error').show().text('请选择');
                $('#renid_error').parent().find('input').addClass('select_error');
            }else{
                $('#renid_error').hide();
                $('#renid_error').parent().find('input').removeClass('select_error');
            }
        });



        form.on('radio(tiaotype)',function (data) {
            if(data.value == 1){
                $("#tiaotypemsg").text('被退回的节点或审核人完成审核后，将自动跳过此前已经审核通过的节点，回到操作退回的审核人。');
            }else{
                $("#tiaotypemsg").text('退回指定节点或审核人完成审核后，此前已经审核过的节点需重新审核。');
            }
        });


        form.on('radio(chongtype)',function (data) {
            if(data.value == 1){
                $("#chongtypemsg").text('申请人重新提交后，系统根据申请人编辑后的内容匹配路线并重走。');
            }else{
                $("#chongtypemsg").text('申请人再次提交后，直接回到当前审核人审核。');
            }
        });


        form.on('submit(add)', function(data){
            var validRes = true;
            if(data.field.tuitype == 1){
                if(data.field.renid == ''){
                    $('#renid_error').show().text('请选择');
                    $('#renid_error').parent().find('input').addClass('select_error');
                    validRes = false;
                }else{
                    $('#renid_error').hide();
                    $('#renid_error').parent().find('input').removeClass('select_error');
                }
            }
            if(data.field.tuitype == 2){
                if(data.field.jieid == ''){
                    $('#jieid_error').show().text('请选择');
                    $('#jieid_error').parent().find('input').addClass('select_error');
                    validRes = false;
                }else{
                    $('#jieid_error').hide();
                    $('#jieid_error').parent().find('input').removeClass('select_error');
                }
            }
            if(!validRes){return false;}



            if(data.field.tuitype == 1){
                data.field.tuiid = data.field.renid;
            }else{
                data.field.tuiid = data.field.jieid;
                if(data.field.jieid == 0){
                    data.field.tiaotype = data.field.chongtype;
                }
            }

            delete data.field.renid;
            delete data.field.jieid;
            delete data.field.chongtype;

            data.field.id = param_id;
            data.field.ispc = 1;
            data.field.promer = tan_tags_getvalue("#promer", 'user');
            data.field.files = public_upload_file_value_str('upload_files');

            facade.ajax({url: ask_flow_examine_bill, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    facade.success('操作成功');
                    setTimeout(function () {
                        parent.window.location.reload();
                    },1500);
                }
            });

            return false;
        });
    });








    function show_flow_used(data) {
        var str = '';
        for (var key in data){
            str += '<div class="tag-box-div">';
            str += '<span class="tag-name" onclick="pushFlowUsed(this)">'+data[key].explain+'</span>';
            str += '<span class="tag-close" onclick="delFlowUsed('+data[key].id+')">×</span>';
            str += '</div>';
        }
        $("#flow_used_div").html(str);
    }

    function addFlowUsed() {
        var explain = $('#explain').val() || '';
        if(!explain){
            facade.error('请填写处理意见');return false;
        }
        layui.use(['laytp', 'form'], function() {
            var form = layui.form, layer = layui.layer;
            facade.ajax({url: ask_opt_add_flow_used, data:{explain:explain}}).done(function(res){
                if (res.code === 2000) {
                    show_flow_used(res.data);
                    render_from();
                }
            });
        });
    }

    function pushFlowUsed(obj){
        var value = $(obj).text();
        var explain = $('#explain').val();
        $('#explain').val(value);
    }

    function delFlowUsed(id){
        layui.use(['laytp', 'form'], function() {
            var form = layui.form, layer = layui.layer;

            facade.ajax({url: ask_opt_del_flow_used, data:{id:id}}).done(function(res){
                if (res.code === 2000) {
                    show_flow_used(res.data);
                    render_from();
                }
            });
        });
    }

</script>
</body>
</html>
